package com.example.word_book.service;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.word_book.R;
import com.example.word_book.bean.Word;
import com.example.word_book.utils.SqlHelp;

import java.util.ArrayList;
import java.util.Date;

public class ViewErrorActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_error);


        init();
    }

    private void init() {
        ImageView back = findViewById(R.id.img_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        ArrayList<Word> words = new SqlHelp(this).selectErrorWordForDay(null);
        ListView lv = findViewById(R.id.lv_error);
        lv.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return words.size();
            }

            @Override
            public Object getItem(int i) {
                return words.get(i);
            }

            @Override
            public long getItemId(int i) {
                return i;
            }

            @Override
            public View getView(int i, View view, ViewGroup viewGroup) {
                view = View.inflate(ViewErrorActivity.this, R.layout.list_item_word, null);
                TextView word = view.findViewById(R.id.tv_word);
                TextView heat = view.findViewById(R.id.tv_heat);
                word.setText(words.get(i).getWord());
                heat.setText(String.valueOf(words.get(i).getHeat()));
                return view;
            }
        });
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(ViewErrorActivity.this,BrowseWordActivity.class);
                intent.putExtra("word",words.get(i).getWord());
                startActivity(intent);

            }
        });
    }
}